<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:spry="http://ns.adobe.com/spry">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Session Expired Sample</title>
<link href="../../css/samples.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.product {
	cursor: pointer;
}
.hover {
	background-color: #FFFFCC !important;
}
.selected {
	background-color: #CCCCCC;
}
</style>
<script src="../../includes/xpath.js" type="text/javascript"></script>
<script src="../../includes/SpryData.js" type="text/javascript"></script>
<script type="text/javascript">

<!--
//
// Create an XMLDataSet to load the states.
//
var dsStates = new Spry.Data.XMLDataSet("../../data/states/states.xml", "/states/state");

//
// Create an XMLDataSet to load the cities for the current state.
// This points to a dynamic page that will "session expire" after 5 calls, so a re-login is required.
//

var dsCities = new Spry.Data.XMLDataSet("GetCities.asp?state={dsStates::name}", "/state/cities/city[position() >=1 and position() <= 30]", {useCache:false});

//
// Add and observer for the dsCities DataSet for the onSessionExpired event.
//
dsCities.addObserver({onSessionExpired: function(dataSet, req){
	Spry.Debug.debugOut("XMLDataset::dsCities: onSessionExpired fired!");
}
});

//
// Add and observer for the 'cities' spry:region for the onExpired event.
//
Spry.Data.Region.addObserver("cities", {onExpired: function(notifier, data) {
	Spry.Debug.debugOut("Region::cities: onExpired fired!");
}
});
//-->
</script>
</head>

<body>
<h3>Session Expired sample</h3>
<p>This page demonstrates how to detect and handle the case when the server is reporting that a session has expired.</p>
<p>It requires asp scripting enabled on the server.</p>
<p>
	 The list of cities on the right side of the states is loaded by the 'dsCities' XMLDataSet using a server page that receives the state name as a parameter. <br/>
	 However, this page throws a session expired message after five requests (five clicks on the states), so the &quot;expired&quot; state for that spry:region is going to be displayed.
</p>
<p>
	By default, XMLDataSet looks for "session expired" message in the text response that comes from the server or in the XML-formatted response.
  If such a message is found, the "expired" state is set for all the spry:regions that depend on the current DataSet.
</p>

<hr />


<table width="100%" border="0">
	<tr>
		<td width="21%" valign="top">
		
			<div spry:region="dsStates">
				<ol spry:state="ready" spry:repeatchildren="dsStates">
					<li class="product" spry:setrow="dsStates" spry:select="selected" spry:hover="hover">{name}</li>
				</ol>
			</div>
			
		</td>
	  <td width="79%" valign="top">
	  		<br/>
				<div spry:region="dsCities dsStates" id="cities">
					<div spry:state="ready">
						<strong>The first 30 cities in the state of &quot;{dsStates::name}&quot;:</strong>
						<ol>
							<li spry:repeat="dsCities">{name}</li>
						</ol>
					</div>
					<div spry:state="loading">Loading cities..</div>
					<div spry:state="error">
							Error loading cities.. <br/>
							This sample requires <strong>asp support</strong> on the server.
					</div>
					<div spry:state="expired">
						<strong>Your session has expired!</strong> <br/>
						You need to re-login in order to access the list of cities. <br/>
						Username / password: admin / pass12 <br/>
						<br/>
						<form id="form1" name="form1" method="post" action="HandleLoginForSessionExpired.asp">
								<div>
										<div>Username:</div>
										<input name="username" type="text" id="username" value=""/>
								</div>
								<div>
										<div>Password:</div>
										<input name="pass" type="password" id="pass" value=""/>
								</div>
								<div>
										<input type="submit" value="Login"/>
								</div>
						</form>
						
					</div>
				</div>	
	  </td>
  </tr>
</table>

<hr/>

<p>
	What is the response required from the server in order for XMLDataSet to detect &quot;session expired&quot; state?
</p>
	<ul>
		<li>Send this string as the response:
		<pre>session expired</pre>
		</li>
		<li>Send this xml as the response:
		<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;reply&gt;session expired&lt;/reply&gt;</pre>
		</li>
		<li>Send any kind of response, but make sure to pass a checker function to the XMLDataSet that will lookup your custom response:
 		<pre>// the checker receives a request object
function MySessionExpiredChecker(req)
{
	  if (req.xhRequest.responseText == 'my custom session expired string')
		    return true;
	  return false;
}
// pass this function to the dataset
ds1.setSessionExpiredChecker(MySessionExpiredChecker);</pre>
		</li>
					
	</ul>

</body>
</html>
 
